package com.kalemao.library.imageview.glide;

import android.content.Context;
import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.load.engine.cache.ExternalCacheDiskCacheFactory;
import com.bumptech.glide.module.GlideModule;
import com.kalemao.library.logutils.LogUtil;
import java.io.File;

public class WSGlideModule implements GlideModule {
    private static final String TAG = "WSGlideModule";

    private static final int M                   = 1024 * 1024;
    private static final int MAX_DISK_CACHE_SIZE = 256 * M;

    /**
     * ************************ Memory Cache ************************
     */

    static void clearMemoryCache(Context context) {
        Glide.get(context).clearMemory();
    }

    /**
     * ************************ GlideModule override ************************
     */
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        // sdcard/Android/data/com.netease.nim.demo/glide
        final String cachedDirName = "ewanse";
        builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, cachedDirName, MAX_DISK_CACHE_SIZE));
        LogUtil.i(TAG, "WSGlideModule apply options, disk cached path=" +
                       context.getExternalCacheDir() +
                       File.pathSeparator +
                       cachedDirName);
    }

    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {

    }
}
